<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Spaghetti Coders</title>
<link rel="stylesheet" type="text/css" href="includes/style.css">
</head>

<body>

<?php

$username = $_SERVER['PHP_AUTH_USER'];

include "includes/lib.php";
include "includes/header.php"; 
include "includes/nav.php";



echo '<div id="wrapper">';
echo '<div id="content">';


if (isset($_GET["action"]) == false) {

	echo 'ERROR: No action defined.';
}
else {
	switch($_GET["action"]) {

	case "list_packages":
		echo "<h3> All Software Packages </h3> <br />";
		list_all_software();
		break;

	case "view":
		if (isset($_GET["pkg_id"]) == false) {
			echo "ERROR: No pkg_id defined.";
		}
		else {
			$pkg_id = mysql_real_escape_string($_GET["pkg_id"]);
			view_pkg($pkg_id);
		}
		break;

	case "create_form":
                        echo '<h3> Add Software Package </h3><br />';
                        echo '<form action ="software.php?action=create_package" method="post">';
                        echo 'Package Name <input type="text" name="pkg_name"><br />';
                        echo 'Description: <input type="text" name="pkg_desc"><br />';
                        echo '<input type="Submit" value="Submit">';
                        echo '</form>';
                break;

	case "update_package":
		if (isset($_GET["pkg_id"]) == false) {
			echo "ERROR: No pkg_id defined.";
		}
		else {
			$pkg_id = mysql_real_escape_string($_GET["pkg_id"]);
			update_pkg_form($pkg_id);
		}
		break;


	case "edit_packages":
		echo "<h3> Edit Software Packages </h3> <br />";
		edit_packages();
		break;




	case "create_package":
		if (isset($_POST['pkg_name']) and isset($_POST['pkg_desc'])) {
			$pkg_name = mysql_real_escape_string($_POST['pkg_name']);
			$pkg_desc = mysql_real_escape_string($_POST['pkg_desc']);
			create_package($pkg_name,$pkg_desc);
			echo "<h3> All Software Packages </h3><br />";
			list_all_software();
		}
		else {
			echo "Error:  Unable to create package.  Insufficient information.";
		}
		break;
	case "mod_pkg":
		if (isset($_POST['pkg_name']) and isset($_POST['pkg_desc']) and isset($_GET['pkg_id'])) {
			$pkg_id = mysql_real_escape_string($_GET['pkg_id']);
			$pkg_name = mysql_real_escape_string($_POST['pkg_name']);
			$pkg_desc = mysql_real_escape_string($_POST['pkg_desc']);
			mod_pkg($pkg_id,$pkg_name,$pkg_desc);
			echo "<h3> All Software Packages </h3><br />";
			edit_packages();
		}
		else {
			echo "Error:  Unable to modify package.  Insufficient information.";
		}
		break;



	default:
		echo "No such action";
		break;
	}
}
?>	
</div>
</body>
</html>

